import {take, call, put, fork, cancel} from 'redux-saga/effects';
import AuthManager from '../services/auth'
import * as Actions from '../actions/index'
import * as Types from '../actions/ActionTypes.js'
import * as api from '../services/order';
import {message} from 'antd';
import callServiceApi from './utils';

function* watchOrderApply() {
  while (true) {
    const { payload } = yield take(Types.ORDER_APPLY.REQUEST);
    yield fork(orderApply, payload);
  }
}
/**
 * 待审批签约信息查询列表
 */
function* watchOrdersQuery() {
  while (true) {
    yield take(Types.ORDERS_QUERY.REQUEST);
    yield fork(ordersQuery);
  }
}

/**
 * 待审批签约信息查询单个
 */
function* watchOrderQuery() {
  while (true) {
    const { payload } = yield take(Types.ORDER_QUERY.REQUEST);
    yield fork(orderQuery, payload);
  }
}

/**
 * 待审批签约信息查询单个
 */
function* watchTimeLineQuery() {
  while (true) {
    const { payload } = yield take(Types.TIMELINE_QUERY.REQUEST);
    yield fork(timeLineQuery, payload);
  }
}

/**
 * 审批某个签约信息
 */
function* watchOrderCheck() {
  while (true) {
    const { payload } = yield take(Types.ORDER_CHECK.REQUEST);
    yield fork(orderCheck, payload);
  }
}

function* orderApply(payload) {
  yield fork(callServiceApi, Actions.orderApply, api.submitOrderApply, payload);
}

function* ordersQuery() {
  yield fork(callServiceApi, Actions.ordersQuery, api.queryOrdersForCheck, {});
}

function* orderQuery(id) {
  yield fork(callServiceApi, Actions.orderQuery, api.queryOrderForCheck, id);
}

function* timeLineQuery(studentId) {
  yield fork(callServiceApi, Actions.timeLineQuery, api.queryTimeLines, studentId);
}

function* orderCheck(order) {
  yield fork(callServiceApi, Actions.orderCheck, api.checkOrder, order);
}

export default function*() {
  yield [
    fork(watchOrderApply),
    fork(watchOrdersQuery),
    fork(watchOrderQuery),
    fork(watchTimeLineQuery),
    fork(watchOrderCheck),
  ];
}
